﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BaBaoFan.Modifier.Model;
using BaBaoFan.Modifier.Service;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;

namespace BaBaoFan.Modifier.Controllers
{
    public class AlgorithmController : BaseController
    {
        private readonly IAlgorithmService _algorithmService;
        public AlgorithmController(IAlgorithmService algorithmService, IMemoryCache memoryCache) : base(memoryCache)
        {
            _algorithmService = algorithmService;
        }
        public IActionResult List()
        {
            var algorithms = _algorithmService.GetCoinAlgorithms();
            return View(algorithms);
        }
        public IActionResult Delete(int[] ids)
        {
            _algorithmService.Delete(ids);
            return Json("ok");
        }
        [HttpGet]
        public IActionResult Add()
        {
            return View();
        }
        [HttpPost]
        public IActionResult Add(CoinAlgorithm coinAlgorithm)
        {
            _algorithmService.Add(coinAlgorithm);
            return Redirect("/Algorithm/List");
        }
        [HttpGet]
        public IActionResult Edit(int id)
        {
            var model = _algorithmService.GetCoinAlgorithmById(id);
            return View(model);
        }
        [HttpPost]
        public IActionResult Update(CoinAlgorithm model)
        {
            _algorithmService.Update(model);
            return Redirect("/Algorithm/List");
        }

        public IActionResult Test()
        {
            return View();
        }
    }
}